<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Project"%>
<%@page import="db.ProjectDAO"%>
<%@page import="db.SubstoreDAO" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ProjectDAO projectDAO = (ProjectDAO)ctx.getBean("ProjectDAO");
	SubstoreDAO substoreDAO = (SubstoreDAO)ctx.getBean("SubstoreDAO");
	List list = substoreDAO.findAll();
	request.setAttribute("substore",list);
	request.setCharacterEncoding("utf-8");
	String sid = request.getParameter("sid");
	int tid = (Integer)session.getAttribute("tid");
	int id = 0;
	if(sid!=null){
		id = Integer.parseInt(sid);
	}
	String substoreid = request.getParameter("subselect");
	int subid = 0;
	if(substoreid==null || "".equals(substoreid)){
		subid = 0;
	}else{
		subid = Integer.parseInt(substoreid);
	}
	request.setAttribute("subid",subid);
	String message = "";
	
	String type = request.getParameter("type");
	//type=2提交表单
	if(type!=null && (type=="2" || "2".equalsIgnoreCase(type))){
		request.setAttribute("type",2);
		String substore = request.getParameter("substore");
		String procode = request.getParameter("procode");
		String proname = request.getParameter("proname");
		String zprocode = request.getParameter("zprocode");
		String zproname = request.getParameter("zproname");
		String manager = request.getParameter("manager");
		Project project = new Project();
		project = projectDAO.findById(id);
		if(procode==null || "".equals(procode)){
			message = "修改项目信息失败，项目编码不能为空。";
			request.setAttribute("message",message);
			request.setAttribute("suess",false);
			pageContext.forward("/vm/prinfo/mod_prinfo.vm");
			return;
		}
		
		//名称不可为空
		if(proname==null || "".equals(proname)){
			message = "修改项目信息失败，项目名称不能为空。";
			request.setAttribute("message",message);
			request.setAttribute("suess",false);
			pageContext.forward("/vm/prinfo/mod_prinfo.vm");
			return;
		}
		int sub = 1;
		if(substore!=null && !"".equals(substore)){
			sub = Integer.parseInt(substore);
		}else{
			sub = 1;
		}
		
		
		if(zprocode==null){
			zprocode="";
		}
		
		if(zproname==null){
			zproname="";
		}
		if(manager==null){
			manager="";
		}
		project.setCode(procode);
		project.setSubstoreId(subid);
		project.setName(proname);
		project.setSubCode(zprocode);
		project.setSubName(zproname);
		project.setManager(manager);
		//project.setTeamId(tid);
		projectDAO.attachDirty(project);
		message = "恭喜您！修改项目信息成功！";
		request.setAttribute("message",message);
		request.setAttribute("suess",true);
		request.setAttribute("sid",id);
		pageContext.forward("/vm/prinfo/mod_prinfo.vm");
		return;
	}else{
	//正常显示
		Project project = new Project();
		project = projectDAO.findById(id);
		request.setAttribute("project",project);
		request.setAttribute("type",1);
		request.setAttribute("sid",id);
		pageContext.forward("/vm/prinfo/mod_prinfo.vm");
	}
	
%>
